package chapter11;

import org.junit.Test;

import java.util.*;

/**
 * @author : DuJiabao
 * @Date : 2021/2/19 19:45
 * @Project : thinking-in-java
 * @File : null.java
 * @Desc :
 */
public class SetTest {
  @Test
  public void hashSetTest() {
    Set<Integer> set = new HashSet<Integer>();
    Random rand = new Random();
    for (int i = 0; i < 1000; i++) {
      set.add(rand.nextInt(30));
    }
    System.out.println(set);
  }

  @Test
  public void treeSetTest() {
    Set<Integer> set = new TreeSet<>();
    set.add(53);
    set.add(1);
    set.add(4);
    set.add(-14);
    set.add(4);
    set.add(434);
    set.add(5);
    System.out.println(set);
  }

  @Test
  public void testContains() {
    Set<String> set = new HashSet<>();
    Collections.addAll(set, "4 4 523 54 fsf 3532 54".split(" "));
    System.out.println(set); // [4, 523, 3532, fsf, 54]
    System.out.println(set.contains("4"));  // true
  }

}
